/*
 * @Autor: taobo
 * @Date: 2020-09-23 21:03:24
 */
#pragma once

#include <stdint.h>
#include <atomic>

class LockFreeQueue {
public:
  LockFreeQueue(uint32_t size);

  ~LockFreeQueue();

  bool put(const uint8_t *buffer, uint32_t len);

  bool get(uint8_t *buffer, uint32_t len);

  inline uint32_t size() { return _size; }
  inline uint32_t length() { return (_in - _out); }
  inline bool empty() { return _in <= _out; }

private:
  uint8_t *_buffer;
  uint32_t _size;
  std::atomic<uint32_t> _in;
  std::atomic<uint32_t> _out;
};